package com.ai.core.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ai.core.cache.AICacheManager;
import com.ai.core.constant.GlobalConstant;
import com.ai.core.entity.InterfaceDef;
import com.ai.core.service.InterfaceDefService;

@Service
public class InterfaceDefServiceImpl implements InterfaceDefService {
	private AICacheManager aiCacheManager = AICacheManager.getInstance();

	private Map m_interface_def = null;

	@Autowired
	private com.ai.core.dao.BaseDaoI<InterfaceDef> interfaceDefDao;

	public InterfaceDefServiceImpl() {
		if (m_interface_def == null) {
			m_interface_def = aiCacheManager.getMap(GlobalConstant.CACHE_INTERFACE_DEF);
		}
	}

	public void loadCache() {
		m_interface_def.clear();
		getAllInterfaceDef();
	}

	public List<InterfaceDef> getAllInterfaceDef() {
		String hql = "from InterfaceDef where state = 1";
		List<InterfaceDef> interfaceDefList = interfaceDefDao.find(hql);
		for (InterfaceDef interfaceDef : interfaceDefList) {
			m_interface_def.put(interfaceDef.getInterfaceId(), interfaceDef);
		}
		return interfaceDefList;
	}
}
